<?php
/*
	Copyright 2006, 2007, 2008, 2009, 2010 Bastiaan Grutters
    
    This file is part of Ages of Strife website.

    Ages of Strife website is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Ages of Strife website is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Ages of Strife website.  If not, see <http://www.gnu.org/licenses/>.
 */
include( '../global/initialize.php' );

include( "../global/adodb-time.inc.php" );

if( isset( $_GET[ 'date' ] ) && formatInput( $_GET[ 'date' ] ) != '' ) {
	$date = formatInput( $_GET[ 'date' ] );
	$date = split( '-', $date );
	
	$turn = getCurrentTurn();
	
	if( is_numeric( $date[0] ) && is_numeric( $date[1] ) && is_numeric( $date[2] ) ) {
		$date = $date[0] . "-" . $date[1] . "-" . $date[2];
	    $query = "SELECT history_id, title, ruler_id, anonymous " .
    		"FROM history " .
    		"WHERE visible = 1 AND turn <= $turn AND date = '$date' " .
    		"ORDER BY title ASC";
	    $result = mysql_query( $query ) or die( "Query failed : " . mysql_error() );
	    $num = mysql_numrows( $result );
		$i = 0;
		while ( $i < $num ) {
		    $query2 = "SELECT seen " .
	    		"FROM history_seen " .
	    		"WHERE ruler_id = " . $_SESSION[ 'ruler_id' ] . " AND history_id = " . mysql_result( $result, $i, "history_id" );
		    $result2 = mysql_query( $query2 ) or die( "Query failed : " . mysql_error() );
			$row2 = mysql_fetch_array( $result2, MYSQL_ASSOC );
			if( isset( $row2[ 'seen' ] ) && $row2[ 'seen' ] == 0 ) {
				$title = "<strong>" . mysql_result( $result, $i, "title" ) . "</strong>";
			}
			else {
				$title = mysql_result( $result, $i, "title" );
			}
			
			if( mysql_result( $result, $i, "ruler_id" ) != -1 && mysql_result( $result, $i, "anonymous" ) == 0 ) {
			    $query2 = "SELECT name " .
		    		"FROM ruler " .
		    		"WHERE ruler_id = " . mysql_result( $result, $i, "ruler_id" );
			    $result2 = mysql_query( $query2 ) or die( "Query failed : " . mysql_error() );
				$row2 = mysql_fetch_array( $result2, MYSQL_ASSOC );
				$by = " " . translate( "by" ) . " <a href=\"../overview/ruler.php?name=" . $row2[ 'name' ] . "\">" . $row2[ 'name' ] . "</a>";
			}
			else {
				$by = ' ' . translate( "by World News Reporter" );
			}
			
			print( "<a href=\"history.php?id=" . mysql_result( $result, $i, "history_id" ) . "\">$title</a>$by<br />" );
			$i ++;
		}
	}
}
?>
